const Nightmare = require('nightmare')
const chai = require('chai')
const expect = chai.expect;

const opt = {
    waitTimeout: 8000 // in ms
}

describe('Load a Page', function() {
    // Recommended: 5s locally, 10s to remote server, 30s from airplane ¯\_(ツ)_/¯
    this.timeout('30s')

    let nightmare = null
    beforeEach(() => {
        nightmare = new Nightmare(opt)
    })

    describe('Open Page https://www.baidu.com/', () => {
        it('should load without error', done => {
            nightmare.goto('https://www.baidu.com/')
                .on('page', (type, message) => {
                    console.log('page load');
                })
                .wait('input[type=submit]')
                .evaluate(() => document.querySelector('input[type=submit]').value)
                .end()
                .then(text => {
                    expect(text).to.equal('百度一下')
                    done()
                })
                .catch(done)
        })
    });
})